package cn.wh.org.controller;

import cn.wh.basic.util.AjaxResult;
import cn.wh.basic.util.PageList;
import cn.wh.org.domain.DictionaryType;
import cn.wh.org.query.DictionaryTypeQuery;
import cn.wh.org.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dic")

public class DictionaryTypeController {

    @Autowired
    private IDictionaryTypeService dictionaryTypeService;


    @GetMapping("/{id}")

    public DictionaryType queryById(@PathVariable Long id){
        return dictionaryTypeService.queryById(id);
    }

    @GetMapping
    public List<DictionaryType> queryAll(){
        return dictionaryTypeService.queryAll();
    }

    @PostMapping
    public PageList<DictionaryType> queryPage(@RequestBody DictionaryTypeQuery query){
        return dictionaryTypeService.queryPage(query);
    }

    @PutMapping
    public AjaxResult addOrUpt(@RequestBody DictionaryType dictionaryType){
        try {
            if (dictionaryType.getId() == null){
                dictionaryTypeService.save(dictionaryType);
            }else{
                dictionaryTypeService.update(dictionaryType);
            }
            return AjaxResult.my();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("弄给和hiGV橘郡");

        }

    }

    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Long id){
        try {
            dictionaryTypeService.removeById(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("弄给和hiGV橘郡");
        }
    }

    @DeleteMapping
    public AjaxResult removeAll(@RequestBody List<Long> ids){
        try {
            dictionaryTypeService.deleteAll(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("弄给和hiGV橘郡");
        }
    }
}
